package com.uchengwang.functions.glide;

import android.content.Context;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool;
import com.bumptech.glide.load.engine.cache.DiskCache;
import com.bumptech.glide.load.engine.cache.ExternalCacheDiskCacheFactory;
import com.bumptech.glide.load.engine.cache.LruResourceCache;
import com.bumptech.glide.load.engine.cache.MemorySizeCalculator;
import com.bumptech.glide.module.GlideModule;

/**
 * Created by U城网 on 2017/5/3.
 * Glide配置信息
 */

public class SimpleGlideModule implements GlideModule {
    private int memorySize = (int) (Runtime.getRuntime().maxMemory()) / 8;// 取1/8最大内存作为最大缓存
    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
//设置格式
        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
        //缓存到外部磁盘SD卡上,字节
        builder.setDiskCache(new ExternalCacheDiskCacheFactory(context,DiskCache.Factory.DEFAULT_DISK_CACHE_DIR, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
        //设置内存缓存大小
        MemorySizeCalculator calculator = new MemorySizeCalculator(context);
        int defaultMemoryCacheSize = calculator.getMemoryCacheSize();// 默认内存大小
        int defaultBitmapPoolSize = calculator.getBitmapPoolSize();// 默认图片池大小

        builder.setMemoryCache(new LruResourceCache(memorySize));
        builder.setBitmapPool(new LruBitmapPool(memorySize));
    }

    @Override
    public void registerComponents(Context context, Glide glide) {

    }
}
